package cn.com.chengmandian.netty.container;

import cn.com.chengmandian.netty.pojo.ChannelCache;
import io.netty.channel.Channel;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

public class ChannelContainer {
    private static Map<String, ChannelCache> channels = new ConcurrentHashMap<>();

    private static Map<String, String> controls = new ConcurrentHashMap<>();

    public static boolean checkChannel(String key) {
        return channels.containsKey(key);
    }

    public static void putChannel(String key, String deviceNo, Channel channel) {
        ChannelCache channelCache = new ChannelCache();
        channelCache.setDeviceNo(deviceNo);
        channelCache.setChannel(channel);
        putChannel(key, channelCache);
    }

    public static void putChannel(String key, ChannelCache channel) {
        channels.put(key, channel);
    }

    public static ChannelCache getChannel(String key) {
        return channels.get(key);
    }

    public static void removeChannel(String key) {
        channels.remove(key);
    }

    public static void putControl(String channelId, String msgId) {
        controls.put(channelId, msgId);
    }
    public static String getControl(String channelId) {
        return controls.get(channelId);
    }
}
